#ifndef SHADER_PROGRAM_H
#define SHADER_PROGRAM_H

#include <QOpenGLFunctions>
#include <QOpenGLShader>
#include <QOpenGLShaderProgram>

class ShaderProgram : protected QOpenGLFunctions {
    public:
        explicit ShaderProgram(const char* vetexShaderSrc, const char* fragmentShaderSrc);
        virtual ~ShaderProgram();

        virtual void initLocations();

    public:
        inline void setAttribute(int attr, int elementCnt, int stride, int start) {
            glVertexAttribPointer(attr, elementCnt, GL_FLOAT, GL_FALSE
                    , stride
                    , reinterpret_cast<void *>(start));
        };
        inline void enableAttribute(int attr) {
            m_program->enableAttributeArray(attr);
        };
        inline void bind() {
            m_program->bind();
        };
        inline void release() {
            m_program->release();
        };
        inline QOpenGLShaderProgram *getProgram() {
            return m_program;
        };
        inline int getAttrPosition() {
            return m_aPostion;
        };
        inline int getUniformProjMatrix() {
            return m_uProjMatrix;
        };

    protected:
        QOpenGLShaderProgram *m_program = nullptr;

    private:
        QOpenGLShader *m_vshader = nullptr;
        QOpenGLShader *m_fshader = nullptr;
        int m_aPostion = -1;
        int m_uProjMatrix = -1;
};
#endif // SHADER_PROGRAM_H
